#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N=2e5;
const int maxn=1e6;
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	int n;
        cin>>n;
        if(n==2)//特判2不满足要求
        {
            cout<<"-1"<<endl;
            return;
        }
        int k=1;
        for(int i=0;i<n;i++)//先依次输出奇数,再依次输出偶数
        {
            for(int j=0;j<n;j++)
            {
                cout<<k<<" ";
                k=k+2;
                if(k>n*n)
                    k=2;
            }
            cout<<endl;
        }


}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}